<?php

/**
 * @name IndexController
 * @author 6p2b7gaqkyoe4aw\administrator
 * @desc 默认控制器
 * @see http://www.php.net/manual/en/class.yaf-controller-abstract.php
 */

error_reporting(E_ALL^E_NOTICE^E_WARNING);
class BaseController extends Yaf_Controller_Abstract {

	public function init(){
	   
		$arrConfig = Yaf_Application::app()->getConfig();
		$this->arrConfig=$arrConfig;
		$this->salt=$arrConfig->database->params->salt;
		$this->salt_time=$arrConfig->database->params->salt_time;
		//$salt=$arrConfig->database->params->salt;
		$this->info=json_decode(file_get_contents("php://input"),true);
		
		
	}
	
	public function checklogin1(){
		if(md5($this->salt.$_SESSION['user_token_time'].$_SESSION['user_id'])!=$_SESSION['user_token']){
			exit(json_encode(array('status'=>0,'info'=>'请先登陆后操作')));
		}
	}
	
	public function checklogin2(){
		$info=json_decode(file_get_contents("php://input"),true);
		$salt=$info['salt'] ? $info['salt'] : $_REQUEST['salt'];
		if(!$salt){exit(json_encode(array('status'=>0,'info'=>'参数不得为空')));}
		
		$where['salt= ?']=$salt;
		
		$usermodel=new UserModel();
		$user=$usermodel->getuser($where);
	
		if(!$user || ($user['salt_time']+$this->salt_time) < time()){
			exit(json_encode(array('status'=>0,'info'=>'登陆状态超时')));
		}
		
		return $user;
	}
	
	
}
